package com.dayatang.hrm.compensation.infra.hibernate;

import java.util.Date;
import java.util.List;

import org.apache.tapestry5.hibernate.HibernateSessionManager;

import com.dayatang.commons.repository.EntityRepositoryHibernateTapestry;
import com.dayatang.hrm.compensation.domain.SalaryAccountSuite;
import com.dayatang.hrm.compensation.domain.SalaryCalculateItem;
import com.dayatang.hrm.compensation.domain.SalaryCalculateItemRepository;
import com.dayatang.hrm.compensation.domain.SalaryItem;
import com.dayatang.hrm.compensation.domain.SalaryItemType;

@SuppressWarnings("unchecked")
public class SalaryCalculateItemRepositoryImpl extends
		EntityRepositoryHibernateTapestry<SalaryCalculateItem, Long> implements
		SalaryCalculateItemRepository {

	public SalaryCalculateItemRepositoryImpl(
			HibernateSessionManager sessionManager) {
		super(SalaryCalculateItem.class, sessionManager);
	}

	@Override
	public List<SalaryItem> findBySalaryItemType(SalaryItemType itemType,
			Date queryDate) {
		return getSessionManager().getSession().getNamedQuery(
				"SalaryItem.findBySalaryItemType").setEntity("pItemType",
				itemType).setTimestamp("pQueryDate", queryDate).list();
	}

	@Override
	public List<SalaryCalculateItem> findSalaryCalculateItemsBySalaryAccountSuite(
			SalaryAccountSuite salaryAccountSuite, Date queryDate) {
		return getSessionManager()
				.getSession()
				.getNamedQuery(
						"SalaryCalculateItem.findSalaryCalculateItemsBySalaryAccountSuite")
				.setEntity("pSuite", salaryAccountSuite).setTimestamp(
						"pQueryDate", queryDate).list();
	}

	@Override
	public List<SalaryItem> findSalaryItemsBySalaryAccountSuite(
			SalaryAccountSuite accountSuite, Date queryDate) {
		return getSessionManager().getSession().getNamedQuery(
				"SalaryItem.findSalaryItemsBySalaryAccountSuite").setEntity(
				"pSuite", accountSuite).setTimestamp("pQueryDate", queryDate)
				.list();
	}

}
